package org.ptkparty.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

public class AddGamePlace extends Place {

	private String name;

	private String game;

	public AddGamePlace(String token) {
		this.name = token;
	}

	public AddGamePlace(String currentChampionship, String id) {
		this.name = currentChampionship;
		this.game = id;
	}

	public String getName() {
		return name;
	}

	public String getGame() {
		return game;
	}

	public static class Tokenizer implements PlaceTokenizer<AddGamePlace> {

		@Override
		public String getToken(AddGamePlace place) {
			StringBuilder sb = new StringBuilder(place.getName());
			if (place.getGame() != null) {
				sb.append("&").append(place.getGame());
			}
			return sb.toString();
		}

		@Override
		public AddGamePlace getPlace(String token) {
			String[] params = token.split("&");
			if (params.length == 1) {
				return new AddGamePlace(params[0]);

			} else if (params.length == 2) {
				return new AddGamePlace(params[0], params[1]);
			}
			return new AddGamePlace("");
		}
	}
}
